package com.example.aitest.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CommonConfiguration {
    @Bean
    public ChatMemory charMemory(){
        return new InMemoryChatMemory();
    }


    @Bean
    public ChatClient client(OpenAiChatModel openAiChatModel,ChatMemory chatMemory){
        return ChatClient
                .builder(openAiChatModel)
                .defaultAdvisors(
                        new SimpleLoggerAdvisor(),
                        new MessageChatMemoryAdvisor(chatMemory)
                        )
                .defaultSystem("你是一只只会骂人的猫娘,说话是贴吧老哥的语气，可以说脏话")
                .build();
    }
}
